﻿//function AddFile(tableid, fileid) {
//    try {
//        tb = document.getElementById(tableid);
//        newRow = tb.insertRow();
//        newRow.insertCell().innerHTML = "&nbsp;&nbsp;<input name='" + fileid + "' id='" + fileid + "' type='file' unselectable='on' style='width: 200px;height:20px' class='EditInPut'>&nbsp;<input type=button class='inputsubmit' value='删除' onclick='document.getElementById(\"" + tableid + "\").deleteRow(this.parentElement.parentElement.rowIndex)'>";
//    }
//    catch (e) { }
//}

var selectid = "";
var Hid = "";
function showAttchments(id, hid, title) {
    selectid = id;
    Hid = hid;
    showDialog('false', title, 'MultiAttchments.aspx', 500, 400, true, true);
}

function CallBackVal(result) {
    try {
        if (selectid == "" || Hid == "" || result == "")
            return;

        var strs = new Array();

        strs = result.split("#");

        if (strs.length == 0)
            return;

        var divText = "";
        var divShow = document.getElementById(selectid);

        for (var i = 0; i < strs.length; i++) {
            if (strs[i] == "")
                continue;

            var tempIndex = strs[i].lastIndexOf('/');

            var suffix = strs[i].substr(tempIndex + 1, strs[i].length).toLowerCase();

            var nameid = suffix.substr(0, suffix.lastIndexOf('.'));

            divText += "<div id='" + nameid + "'><a href='" + strs[i] + "' target='_blank' title='点击查看附件'>" + suffix + "</a>&nbsp;&nbsp;<a href='javascript:' onclick='hidAttchments(\"" + nameid + "\",\"" + strs[i] + "\",\"" + selectid + "\",\"" + Hid + "\")'>删除</a></div>";

            document.getElementById(Hid).value += strs[i] + "#";
        }

        document.getElementById(selectid).style.display = "";
        document.getElementById(selectid).innerHTML += divText;
    }
    catch (e) { }
    finally {
        selectid = "";
        Hid = "";
    }
}

function hidAttchments(id, textVal, selectdiv, hiddiv) {
    document.getElementById(id).style.display = "none";
    document.getElementById(hiddiv).value = document.getElementById(hiddiv).value.replace(textVal + "#", "");

    if (document.getElementById(hiddiv).value == "")
        document.getElementById(selectdiv).style.display = "none";
}

function LoadAttchments() {
    try {
        var obj = document.getElementsByTagName('input');
        for (var j = 0; j < obj.length; j++) {
            if (obj[j].type == 'hidden') {
                if (obj[j].id.indexOf("hidAttch") == 0 && obj[j].value != "") {
                    selectid = obj[j].title;
                    Hid = obj[j].id;
                    var hidval = obj[j].value.substr(0, obj[j].value.lastIndexOf('#'));
                    obj[j].value = "";
                    CallBackVal(hidval);
                }
            }
        }
    }
    catch (e) { }
}